//
//  ZGLOrderPayCell.m
//  ZeegingLottery
//
//  Created by 李曌 on 2018/7/6.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLOrderPayCell.h"

@interface ZGLOrderPayCell ()

@property (nonatomic, strong)UIImageView *payIconImage;
@property (nonatomic, strong)UILabel *payTypeLabel;
//@property (nonatomic, strong)UILabel *yuELable;  //余额
@property (nonatomic, copy)NSString *Balance; //余额
@property (nonatomic, copy)NSString *totalMoney;

@end

@implementation ZGLOrderPayCell

+ (instancetype)orderPayCellWith:(UITableView *)tableView
{
    static NSString *OrderPayCellID = @"OrderPayCell";
    ZGLOrderPayCell *cell = [tableView dequeueReusableCellWithIdentifier:OrderPayCellID];
    if (!cell) {
        cell = [[ZGLOrderPayCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:OrderPayCellID];
    }
    
    return cell;
}


- (void)comparTotalMoney:(NSString *)totalMoney Balance:(NSString *)balance
{
    _totalMoney = totalMoney;
    _Balance = balance;
    double balanceInt = [balance doubleValue];
    double hongBao = [sZGLUserInfoModel.red_cash doubleValue];
    double usable = balanceInt + hongBao;
    NSString *usableStr = [NSString stringWithFormat:@"%.2f",usable];
    NSString *yuEStr = [PublicMethod DigitalNumberWithString:usableStr];
    self.yuELable.text = [NSString stringWithFormat:@"(剩余 ￥%@)",yuEStr];
    if (_totalMoney.integerValue < _Balance.integerValue) {
        
        [self.yuETipLabel setHidden:YES];
    }
    
}

- (void)setNameWith:(NSString *)name Icon:(NSString *)icon
{
    self.payIconImage.image = [UIImage imageNamed:icon];
    self.payTypeLabel.text = name;
    if (![name isEqualToString:@"余额支付"]) {
        [self.yuETipLabel setHidden:YES];
        [self.yuELable setHidden:YES];
    }
    
    if ([name isEqualToString:@"支付宝"] ) {
        NSInteger ali = [self.ali_pay integerValue];
        if (ali == 0) {
            [self.yuELable setHidden:NO];
            self.yuELable.text = @"暂不支持";
        }
    }
    
    if ([name isEqualToString:@"微信支付"] ) {
        NSInteger wechat = [self.weChat_pay integerValue];
        if (wechat == 0) {
            [self.yuELable setHidden:NO];
            self.yuELable.text = @"暂不支持";
        }
    }
    
//    if ([name isEqualToString:@"微信支付"] && [self.weChat_pay intValue]==0) {
//        [self.yuELable setHidden:NO];
//        self.yuELable.text = @"暂不支持";
//    }else{
//        [self.yuELable setHidden:YES];
//    }
    
}


- (void)setWeChat_pay:(NSString *)weChat_pay
{
    _weChat_pay = weChat_pay;
    
}

-(void)setAli_pay:(NSString *)ali_pay
{
    _ali_pay = ali_pay;
}

- (void)canSelectedAli_Pay:(NSString *)ali_pay Wechat:(NSString *)wechat
{
    
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIImageView *payIconImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_loading_default"]];
        _payIconImage = payIconImage;
        [self.contentView addSubview:self.payIconImage];
        
        UILabel *payTypeLabel = [[UILabel alloc]init];
        payTypeLabel.textColor = mainTextColor;
        payTypeLabel.font = [UIFont systemFontOfSize:14];
        payTypeLabel.text = @"支付";
        payTypeLabel.textAlignment = 0;
        _payTypeLabel = payTypeLabel;
        [self.contentView addSubview:self.payTypeLabel];
        
        UILabel *yuELable = [[UILabel alloc]init];
        yuELable.textColor = detailTextColor;
        yuELable.font = [UIFont systemFontOfSize:13];
        yuELable.textAlignment = 1;
        yuELable.text = @"";
        _yuELable = yuELable;
        [self.contentView addSubview:self.yuELable];
        
        UILabel *yuETipLabel = [[UILabel alloc]init];
        yuETipLabel.textColor = detailTextColor;
        yuETipLabel.font = [UIFont systemFontOfSize:13];
        yuETipLabel.textAlignment = 1;
        yuETipLabel.text = @"余额不足";
        _yuETipLabel = yuETipLabel;
        [self.contentView addSubview:self.yuETipLabel];
        
        UIImageView *selectedImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_buy_success"]];
        [selectedImage setHidden:YES];
        _selectedImage = selectedImage;
        [self.contentView addSubview:self.selectedImage];
        
        [self setupContentView];
        
        [HKUIUtils addLineInView:self.contentView color:BorderColor top:NO leftMargin:60 rightMargin:0];
    }
    
    return self;
}

- (void)setupContentView
{
    [_payIconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(20);
        make.centerY.equalTo(self.contentView);
        make.size.equalTo(@(30));
        
    }];
    
    [_payTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_payIconImage.mas_right).offset(15);
        make.centerY.equalTo(_payIconImage);
        
    }];
    
    [_yuELable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_payTypeLabel.mas_right).offset(1);
        make.centerY.equalTo(_payTypeLabel);
        
    }];
    
    [_yuETipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView).offset(-20);
        make.centerY.equalTo(self.contentView);
    }];
    
    [_selectedImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView).offset(-20);
        make.centerY.equalTo(self.contentView);
        make.size.equalTo(@(20));
        
    }];
    
}


@end
